package com.cn.suplayer.ui;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.cn.suplayer.R;
import com.cn.suplayer.bean.VideoDirectories;
import com.cn.suplayer.seahcontrol.SearchControl;

import java.io.Serializable;
import java.util.List;

/**
 * Created by ZLM on 2016/6/16.
 * 主页显示视频目录信息
 */
public class MainActivity extends AppCompatActivity {

    SearchControl searchControl;
    ListView listView;
    Context context;
    List<VideoDirectories> videoDirectories;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_main);
        context=getApplicationContext();
        listView=(ListView)findViewById(R.id.mainListView);

        initData();
        if(videoDirectories.size()>0){
            MainListViewAdapter adapter=new MainListViewAdapter(context,videoDirectories);
            listView.setAdapter(adapter);
        }
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent i=new Intent();
                i.putExtra("videos",(Serializable)videoDirectories.get(position).getVideos());
                i.setClass(context,DirectorDetailsActivity.class);
                startActivity(i);
            }
        });
    }


    public void initData(){
        searchControl=new SearchControl(context);
        videoDirectories= searchControl.getDirectories();
        if(videoDirectories.size()==0){
            Toast.makeText(context,"没有找到什么东西。。。",Toast.LENGTH_SHORT).show();
        }
    }


}
